/**
 * Created by johnson on 17/4/27.
 */
import {Injectable} from '@angular/core';
import {HttpUtils} from "../utils/http.utils";
import {USER} from "./user.service";
import {ParamsModel, PageParam} from "../model/params.model";

@Injectable()
export class USERAPI {
  registerApi = '/common/registration';
  loginApi = '/common/login/username';
  loginByPhoneApi = '/common/login';
  passwordApi = '/common/password'


  constructor(private api:HttpUtils,private USER:USER) {

  }
  public fetchUser(success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = '/customerUser/info';
    pm.succCallback = success;
    this.api.get(pm)
  }

  register(params:Object, success:any) {
    let pm = new ParamsModel(this.USER)
    pm.url = this.registerApi;
    pm.reqestData=params;
    pm.succCallback = success;
    this.api.post(pm);
  }
  modPwd(params:Object, success:any) {
    let pm = new ParamsModel(this.USER)
    pm.url = this.passwordApi;
    pm.reqestData=params;
    pm.succCallback = success;
    this.api.put(pm);
  }

  login(params:Object, success:any) {
    let pm = new ParamsModel(this.USER)
    pm.url = this.loginApi;
    pm.reqestData=params;
    pm.succCallback = success;
    this.api.post(pm);
  }

  loginByVerifyCode(params:Object, success:any) {
    let pm = new ParamsModel(this.USER)
    pm.url = this.loginByPhoneApi;
    pm.reqestData=params;
    pm.succCallback = success;
    this.api.post(pm);
  }

  public fetchMessage(succ,page?:PageParam){
    let pm = new ParamsModel(this.USER);
    pm.url = '/notification';
    pm.reqestData = page;
    pm.succCallback = succ;
    this.api.get(pm);
  }

}
